﻿#ifndef CWorkMng_H
#define CWorkMng_H
/********************************************************************************
** @ Date:2025/04/18
** @ Author: HanJiaXin
** @ Description:跑偏检测业务逻辑类
** @ Version:1.0.0
** @ ClassName:CWorkMng
** @ Fun:
********************************************************************************/
#include <QThread>
#include <QMutex>
#include "CDevDataBeltRealign.h"
#include "CCamerCtrMange.h"

class CWorkMng : public QThread
{
	Q_OBJECT

public:
	CWorkMng(CCamerCtrMange* pCamerCtrMange, CDevDataBeltRealign *pDevDataBeltCorrect);
	~CWorkMng();

	void threadStart();
	void threadStop();

private:
	void updateBeltCorrectState();//查询数据库更新皮带纠偏跑偏数据
	void handleCorrectData();//处理跑偏数据
	void addAlarm(QString& sAlarmDesc);//生成新的报警记录
	void closeAlarm();//闭环当前的报警记录
	void addResult();//生成新的结果记录
	void closeResult();//闭环新的经过记录

protected:
	void run() override;

private:
	bool m_bShouldStop;
	bool m_bFrist;                           //是否是首次开启线程，防止重启启动设备的时候频繁创建线程
	std::atomic<bool>      m_bhread;         //线程状态
	QMutex   *m_pMutex;		                 //线程锁
	bool m_bIsRecord;
	QString m_sLastGuid;
	int m_nResultCount;                      //输出跑偏结果计数
	CCamerCtrMange* m_pCamerCtrMange;        //摄像头控制类
	CDevDataBeltRealign *m_pDevDataBeltRealign;
	int m_nLoginCount;
};

#endif